<template>
    <div>
        <h1>品类-添加品类</h1>
        所属品类:<el-select v-model="value" placeholder="请选择">
            <el-option
            v-for="(item,index) in list"
            :key="index"
            :label=" item.id==0 ?  item.name : '/所有/'+item.name  "
            :value="item.id">
            </el-option>
        </el-select>
        <br/>
        品类名称:<el-input style="width:300px" v-model="name" placeholder="请输入内容"></el-input><br/>
        <el-button type="primary" @click="add">确认</el-button>
    </div>
</template>

<script>
import { getcategory,addcategory } from "../../../http/index.js";

export default {
  data() {
    return {
        list:[
            {
                id:0,
                name:'/所有'
            }
        ],
        value:'',
        name:''
    };
  },
  mounted() {
      this.getcate()
  },
  methods: {
    async getcate() {
      let res = await getcategory();
      console.log(res);
      for(var i=0;i<res.data.data.length;i++){
          this.list.push(res.data.data[i])
      }
      console.log(this.list);
    },
    add(){
        addcategory({parentId:this.value,categoryName:this.name}).then(res=>{
            console.log(res);
            this.$message.success(res.data.data)
            if(res.data.data=="添加品类成功"){
                this.$router.go(-1)
            }
        })

    }
  }
};
</script>

<style lang="scss" scoped>
</style>